home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST10-13.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  1KB  |  53 lines

  1. ;
  2. ; *** Listing 10-13 ***
  3. ;
  4. ; Clears a 1000-byte block of memory via BlockClearW,
  5. ; which handles blocks between 0 and 64K-1 bytes in
  6. ; length. BlockClearW uses STOSW rather than STOSB to
  7. ; the greatest possible extent in order to improve
  8. ; performance.
  9. ;
  10.     jmp    Skip
  11. ;
  12. ARRAY_LENGTH    equ    1000
  13. ByteArray    db    ARRAY_LENGTH dup (?)
  14. ;
  15. ; Clears a block of memory CX bytes in length. A value
  16. ; of 0 means "clear zero bytes," so the maximum length
  17. ; that can be cleared is 64K-1 bytes and the minimum
  18. ; length is 0 bytes.
  19. ;
  20. ; Input:
  21. ;    CX = number of bytes to clear
  22. ;    ES:DI = start of block to clear
  23. ;
  24. ; Output:
  25. ;    none
  26. ;
  27. ; Registers altered: AX, CX, DI
  28. ;
  29. ; Direction flag cleared
  30. ;
  31. BlockClearW:
  32.     sub    ax,ax    ;we'll fill with the value 0
  33.     shr    cx,1    ;divide by 2, copying the odd-byte
  34.             ; status to the Carry flag
  35.     cld        ;make STOSW move DI up
  36.     rep    stosw    ;clear the block
  37.     jnc    ClearDone
  38.             ;the Carry status is still left over
  39.             ; from the SHR. If we had an even #
  40.             ; of bytes, we're done
  41.     stosb        ;clear the odd byte
  42. ClearDone:
  43.     ret
  44. ;
  45. Skip:
  46.     call    ZTimerOn
  47.     mov    di,seg ByteArray
  48.     mov    es,di    ;point ES:DI to the array to clear
  49.     mov    di,offset ByteArray
  50.     mov    cx,ARRAY_LENGTH    ;# of bytes to clear
  51.     call    BlockClearW    ;clear the array
  52.     call    ZTimerOff
  53.